package jdk5.concurrent.pre5;

import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;

import jdk5.concurrent.Worker;

public class FileServer extends Thread {
         private int port;

         public FileServer(int port){
	this.port = port;
        }

        public void run(){
              ServerSocket ss = null;
               try{
                    ss = new ServerSocket(port);
              }catch(IOException e){
                    e.printStackTrace();
                     System.exit(1);
             }
              while(true){
                    try{
                       Socket s = ss.accept();
                       new Thread(new Worker(s)).start();
                    }catch(IOException e){
                           if(ss.isClosed()) break;
                           e.printStackTrace();
                    }
              }
       }
        
}

